#include "stdafx.h"
#include "PlayerData.h"


PlayerData::PlayerData()
:m_bLoadedProgress(false), m_bLoadedForms(false), progress(), forms()
{
}

Progress*
PlayerData::getProgressData()
{
	if (m_bLoadedProgress)		return &progress;
	else						return NULL;
}

Progress*
PlayerData::setProgressData()
{
	m_bLoadedProgress = true;
	return & progress;
}


Forms*
PlayerData::getFormData()
{
	if (m_bLoadedForms)		return &forms;
	else						return NULL;
}

Forms*
PlayerData::setFormData()
{
	m_bLoadedForms = true;
	return & forms;
}

void
PlayerData::setActiveForm(const short ftype)
{
	forms.ftype = ftype;
}




PlayerDataManager::PlayerDataManager()
{
}

PlayerDataManager::~PlayerDataManager()
{
}

PlayerData*
PlayerDataManager::get(const int &nID) const
{
	PlayerDataMap::const_iterator it = m_PlayerDataWMap.find(nID);
	if (it==m_PlayerDataWMap.end())
	{
		return NULL;
	}
	else
	{
		return it->second;
	}
}

PlayerData*
PlayerDataManager::add(const int &nID)
{
	PlayerData* pd = get(nID);
	if (pd==NULL)
	{
		pd = new PlayerData;
		m_PlayerDataWMap[nID] = pd;
	}
	return pd;
}

void
PlayerDataManager::rmv(const int& nID)
{
	PlayerDataMap::iterator it = m_PlayerDataWMap.find(nID);
	if (it!=m_PlayerDataWMap.end())
	{
		delete it->second;
		m_PlayerDataWMap.erase(it);
	}
}
